package edu.example.paperselection;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<Paper> papers = new ArrayList<>();
        papers.add(new Thesis("深度学习在图像识别中的应用"));
        papers.add(new JournalPaper("软件构造课程设计实践"));
        papers.add(new ConferencePaper("敏捷开发模式研讨会"));
        papers.add(new Thesis("分布式系统的性能优化"));
        papers.add(new JournalPaper("Java 设计模式详解"));
        papers.add(new ConferencePaper("人工智能前沿技术"));

        PaperList paperList = new PaperList("张老师", papers);

        Student alice = new Student("Alice", 2, PaperType.JournalPaper);
        Student bob = new Student("Bob", 1, PaperType.Thesis);

        Student charlie = new Student("Charlie", 2, PaperType.Any);

        try {
            List<Paper> aliceSelected = paperList.selectPaperByRandom(alice);
            System.out.println("Alice 选到的论文: " + aliceSelected);

            List<Paper> bobSelected = paperList.selectPaperByRandom(bob);
            System.out.println("Bob 选到的论文: " + bobSelected);

            List<Paper> charlieSelected = paperList.selectPaperByRandom(charlie);
            System.out.println("Charlie 选到的论文: " + charlieSelected);


            paperList.selectPaperByRandom(alice);
        } catch (NoEnoughPapersException e) {
            System.err.println("选论文失败: " + e.getMessage());
        } catch (IllegalArgumentException e) {
            System.err.println("参数错误: " + e.getMessage());
        }

        PaperSelection result = paperList.getSelectionResult();
        StudentCountVisitor studentVisitor = new StudentCountVisitor();
        result.accept(studentVisitor);
        System.out.println("参与选论文的学生数量: " + studentVisitor.getStudentCount());

        PaperCountVisitor paperVisitor = new PaperCountVisitor();
        result.accept(paperVisitor);
        System.out.println("已选论文总数量: " + paperVisitor.getPaperCount());
    }
}